<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<title>${aier_title}</title>
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/jq.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/multiselect.css" />
<link rel="stylesheet" href="${aier_css_url}jc/chosen.css">
<link rel="stylesheet" href="${aier_css_url}jp/msg.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/reset.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/btn.css" />
<link rel="stylesheet" href="${aier_css_url}social/user/ujscb.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/uploadphoto.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/xxs.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}ui.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/ja.js"></script>
<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/afu.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/multiselect.js"></script>
<script type="text/javascript" src="${aier_js_url}social/user/userHSConBook/chibook.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<link rel="stylesheet" href="${aier_css_url}social/module/aier-ui.css" />
<script type="text/javascript" src="${aier_js_url}aier-ui.js"></script>
</head>
<script type="text/javascript">
	var global_suffix = "${aier_suffix}", global_url = "${aier_url}", global_uri = "${aier_uri}", global_urijs = "${aier_urijs}", 
		global_cid = "${cid}", global_tid = "${tid}",global_buid = "${buid}",global_userin_url = "${video_user_in_url}",global_userout_url = "${video_user_out_url}";
</script>
<body data-usertype="家长" class="view-ujscb">
	<!-- 顶栏 -->
	<s:action name="userhomecomm_homeHead" namespace="/user" executeResult="true"></s:action>
	<div class="window-content">
		<!-- wrap  -->
		<div class="wrap clearfix">
			<!-- ^^^左侧导航栏 -->
			<div class="nav-side">
				<!-- 家校联系簿（家长） 头像（孩子的） -->
				<div class="ujscb-userinfo">
					<dl class="clearfix">
						<dt style="" data-log="头像" class="avatar">
							<a href="${aier_url}user/uccomm_userCenter.shtml"> <img src="${get_picturl_url}small/${userInfo.headimg}"></a>
						</dt>
						<dd class="nickname">
							<a href="${aier_url}user/uccomm_userCenter.shtml">${userInfo.nickname}</a>
						</dd>
						<dd class="overage-status">
							<div class="explain">
								<span id = "edate"></span>
								<!--  <a>续费</a>-->
							</div>
						</dd>
					</dl>
				</div>
				<!-- / 管理员头像 -->
				<div class="ujscb-sidetab-parent">
					<div class="nav-item current">
						<a class="btn btn-white-3" href="javascript:void(0);"><span>家校联系簿</span></a>
					</div>
					<div class="nav-item" id = "buyService">
						<a class="btn btn-white-3" href="${aier_url}${aier_uri}pay_selOrders${aier_suffix}?buid=${buid}&bname=${bname}&cid=${cid}"><span>购买应用</span></a>
					</div>
					<div class="nav-item">
						<a class="btn btn-white-3 btn-dialog-usb-intro" href="javascript:void(0);"><span>应用介绍</span></a>
					</div>
					<div class="nav-item" id = "buyRecord">
						<a class="btn btn-white-3" href="${aier_url}${aier_uri}pay_payRecode${aier_suffix}?buid=${buid}&bname=${bname}&cid=${cid}"><span>购买记录</span></a>
					</div>
				</div>
				<!-- ^^^应用介绍 -->
				<s:action name="userhscb_userHSCBintro" namespace="/user" executeResult="true"></s:action>
				<!-- $$$应用介绍 -->
			</div>
			<!-- $$$左侧导航栏 -->
			<!-- 主区域 (右  -->
			<div class="main-area clearfix">
				<!-- 中间栏 -->
				<div class="message-stream">
					<div class="stream-main">
						<div class="right-main-top">
							<div class="binfo-title" id="title">
								<h3>家校联系簿</h3>
							</div>
						</div>

						<div class="sendBox" id = "hsContent">
							<div id="teaSendTabs">
								<!-- 对话 -->
								<div id="inputTalk">
									<div class="sendto clearfix">
										<span class="send-to-left">发送给：</span>
										<div class="send-to-right">
											<select id="sendDialogue" style="width:205px;" multiple="multiple">
												<c:forEach var="sg" items="${ctList }">
                                                    <option value="${sg.tid}">${sg.name_teacher}</option>
                                                </c:forEach>
											</select>
										</div>
									</div>
									<div class="input-box clearfix ">
										<textarea class="placeholder border-box" id="dialogText"
											placeholder="对话可以发给多个老师了，内容只有您和对方可见。" data-maxcount="120"
											data-input-limit-uid="0" data-prevcolor="rgb(0, 0, 0)"
											style="color:#515151;"></textarea>
										<div class="input-bottom clearfix" style="display: none;">
											<span class="fr word-limit" style="visibility: hidden;">"还可以输入"<em>114</em>"个字"</span>
											<span class="doupload" style="visibility: hidden;"> <a
												href="javascript:;" class="upload_img">图片</a>&nbsp;| <a
												href="javascript:;" class="upload_video">视频</a>&nbsp;| <a
												href="javascript:;" class="upload_attach">附件</a> </span>
										</div>
									</div>
									<div class="sendOth">
										<a href="javascript:;" id="dialogSend" class="button sendBtn"><em>发送</em>
										</a>
									</div>
								</div>
								

							</div>



							<div id="teaShowTabs">
								<ul>
									<li><a href="#userDialogue" id = "dialogli">对话</a></li>
									<li><a href="#userTask" id = "task">作业</a></li>
									<li><a href="#userBulletin" id = "bulletin">公告</a></li>
									<li><a href="#userRemark" id = "remark">评语</a></li>
									<!-- <li><a href="#userDailyDining" id = "daily">每日餐饮</a></li>-->
									<li><a href="#userParkRecord" id = "record">进出园记录</a></li>
									<li><a href="#userBindCard" id = "iccard">宝宝IC卡绑定</a></li>
								</ul>
								
								<!-- 公告 -->
								<div id="userBulletin">
									
								</div>
								<!-- 作业 -->
								<div id="userTask">
									<div class="fd-item" id = "homework">
										
									</div>
									
								</div>
								<!-- 每日餐饮 -->
								<!-- <div id="userDailyDining">功能完善中,敬请期待</div>-->
								<!-- 对话 -->
								<div id="userDialogue">
									
									<div class="fd-item" id="dialog">
										
									</div>
								</div>
								<!-- 评语 -->
								<div id="userRemark">
									<div class="fd-item" id ="appraise">
										
									</div>
								</div>

								<!-- 进出园记录 -->
								<div id="userParkRecord">
									<table id="inOutParkInfo"></table>
									<div id="inOutParkPage"></div>
								</div>

								<!-- 宝宝IC卡绑定 -->
								<div id="userBindCard">
									<div class="info-tab01">
										<table id="inviteParTable">
											<tbody>
												<tr>
													<th style="width: 50px;" class="gray6">卡号：</th>
													<td><input id="cardTxt" type="text" class="PY-input" style="width: 150px;">
													</td>

													<th style="width: 70px;" class="gray6">验证码：</th>
													<td><input id="codeTxt" type="text" class="PY-input" style="width: 150px;">

													</td>
													<td width="100px;" align="right"><a id="cardBindBtn"
														onclick="bindStuCard();" href="javascript:;"
														class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"><span
															class="ui-button-text">绑定</span> </a></td>
												</tr>

											</tbody>

										</table>
									</div>
									<div class="down-inre">
										<table id="schoolCardInfo"></table>
										<div id="schoolCardPage"></div>
									</div>
								</div>
							</div>
							<div id = "page"></div>
						</div>
					</div>
					
				</div>

		
			</div>
				<!-- 回到顶部 -->
			<s:action name="userhomecomm_backToTop" namespace="/user" executeResult="true"></s:action>
		</div>
		<!-- footer copyright -->
		<s:action name="userhomecomm_homeFooter" namespace="/user" executeResult="true"></s:action>
		<!-- /footer copyright -->
	</div>
	<!-- 上传图片弹出框 -->
	<div id="uploadPhotoBox" style="z-index:999;display:none;">
	    <div class="title">上传图片</div>
	
	    <div class="select">
	
	        <a class="btn-select">
	            <label for="selectPhoto">
	            <span>选择图片</span>
	            </label>
	        </a>
	
	        <input type="file" id="selectPhoto" style="" name="selectPhoto">
	    </div>
	
	    <div class="uploading" style="display:none">正在上传</div>
	
	    <div id="confirmPhoto" style="display:none">
	        <div id="photoName"></div>
	        <div id="delete">x</div>
	    </div>
	
	</div>
	<!-- /上传图片弹出框 -->

	<div class="layer-popup"></div>
</body>
<script type="text/javascript">
    var bpage = 1;       // 公告的当前页
    var tpage = 1;       // 作业的当前页
    var dpage = 1;       // 对话的当前页
    var rpage = 1;       // 评语的当前页
    var page_size = 10;  // 每页的记录数
    var bname = "${bname}"; // 宝宝姓名
    var curTab = 0;      // 当前选中的是哪个标签页（0对话1作业2公告3评语4进出园记录5宝宝ic卡绑定）
    //var edate = "${edate}";
    
	var hwImg = "";
	
	$("#teaSendTabs").tabs();
	$("#teaShowTabs").tabs();
	$(".chosen").chosen();

	//设置班级为下拉复选框
	$("#sendDialogue").multiselect({
		noneSelectedText : "请选择",
		selectedText : "已选中#个学生",
		selectedList : 3
	});


	//同步加载用户所管理的班级列表

	//同步加载用户所绑定的宝宝

	//文本输入框与textare切换
	//文本框获得焦点
	$(".txt_ipt").focus(function() {
        $(this).hide();
        $(this).closest('.fd-right').find('.comment_input_box').show();
        $(this).closest('.fd-right').find('.comment_input_box textarea').focus();
    });
	
	$(document).ready(
					function() {
						var fun = function(data) {
                            if (data.s == 1) {
                                var baby = data.baby;
                                if (baby == null) {
                                    $().message("您没有权限进入此家校联系薄");
                                    window.history.back();
                                } else {
                                	// 判断是否付费
                                	if (baby.edate == '3') {
                                	   $("#edate").text("");
                                	   document.getElementById("buyService").style.display="none";
                                	   document.getElementById("buyRecord").style.display="none";
                                	} else if (baby.edate == '1') {
                                        // 未购买
                                        $("#edate").text("未购买服务");
                                        $("#hsContent").html("您的家校联系薄暂时不能使用，请购买此服务！");
                                    } else if (baby.edate == '2') {
                                        // 服务过期
                                        $("#edate").text("服务已过期");
                                        $("#hsContent").html("您的家校联系薄服务已过期，请续费！");
                                    } else {
                                        $("#edate").text("有效期至"+baby.edate);
                                    }
                                    $("#title").html("<h3>家校联系薄-" + bname + "</h3>");
                                    // 获取对话列表
                                    searchDialog(dpage);
                                }
                            }
                        };
                        exeAjax(
                                ajaxUrl("${aier_url}${aier_urijs}userhscb_searchBabyByUid${aier_suffix}"),
                                fun, {
                                    "buid" : global_buid
                                });
                        
					});
	// 家长发送对话
	$("#dialogSend")
			.click(
					function() {
						var tidStrOld = $("#sendDialogue").val();
						var tidStr = "" ;
						if (tidStrOld != null) {
						    tidStr = tidStrOld.toString();
						}
						if (isnull(tidStr)) {
							$().message("请选择教师！");
							return;
						}

						var content = $("#dialogText").val();
						if (null == content || "" == content) {
							$().message("请输入对话内容！");
							return;
						}
						var fun = function(data) {
							if (data.s == 1) {
								$("#sendDialogue").attr("value", "");
								$("#sendDialogue").multiselect('refresh');
								$("#dialogText").val("");
								$().message("对话发送成功！");
								// 刷新对话列表
								searchDialog(dpage);
							}
						};
						exeAjax(
								ajaxUrl("${aier_url}${aier_urijs}userhscb_launchPDialog${aier_suffix}"),
								fun, {
									"tidStr" : tidStr,
									"cid" : global_cid,
									"buid" : global_buid,
									"content" : content
								});

					});

    $("#dialogli").click(function() {
        curTab = 0;
        searchDialog(dpage);
    });
	// 获取对话列表
	function searchDialog(nowpage) {
	    dpage = nowpage;
		//dialog
		var fun = function(data) {
			if (data.s == 1) {
				// 刷新对话列表
				var html = "";
				if (data.dialogList != null) {
					for ( var i = 0; i < data.dialogList.length; i++) {
						var dialog = data.dialogList[i];
						html += '<dl class="dldldl clearfix" data-srxtype="talk" ><dt><a class="fd-actor" href=""><img width="50" height="50" data-card="392166" src="${get_picturl_url}small/'+dialog.headimg+'"></a></dt>';
						html += '<dd class="fd-right" data-did="'+dialog.did+'">';
						if (dialog.type == 1) {
							html += '<div class="fd-top"><a href="">'
									+ dialog.tname + '老师</a> 发送给 <a href="">'
									+ dialog.bname + '</a> 家长的对话<br>'
									+ dialog.content + '</div>';
						} else {
							html += '<div class="fd-top"><a href="">'
									+ dialog.bname + dialog.relation
									+ '</a> 发送给 <a href="">' + dialog.tname
									+ '老师</a>的对话<br>' + dialog.content
									+ '</div>';
						}
						html += '<div class="fd-media-pre"></div><p class="fd-bottom"><span class="fd-actions"><a href="javascript:;" data-action="replyIt" id="replyCount_1399030" data-count="4">回复(<em>'
								+ dialog.dcList.length
								+ '</em>)</a></span><span class="time">'
								+ dialog.cdate.split("T")[0]
								+ " "
								+ dialog.cdate.split("T")[1] + '</span></p>';

						if (dialog.dcList != null && dialog.dcList.length != 0) {
							html += '<div id="commentPanel_1399030" class="comment"><div id="commentList_1399030" class="comment_list">';
							for ( var j = 0; j < dialog.dcList.length; j++) {
								var dc = dialog.dcList[j];
								html += '<dl><dt><a href=""><img src="${get_picturl_url}small/'+dc.headimg+'" width="40" height="40" data-card="" alt=""></a></dt><dd class="ml50"><a href="">'
										+ dc.cname
										+ '</a><span class="time">'
										+ dc.cdate.split("T")[0]
										+ " "
										+ dc.cdate.split("T")[1] + '</span>';
								html += '<a href="javascript:;" data-action="replyComment" data-cid="282337" data-cuid="" data-fromuser="" class="reply">回复</a><div class="content mt5"><div>'
										+ dc.content
										+ '</div><div class="media_pre"></div></div></dd></dl>';
							}
							html += '</div>';
						}
						html += '<div class="sj"></div><input type="text" class="txt_ipt" value="我要回复" data-action="showInputBox"><div style="display: none;" class="comment_input_box"><div class="txt_wrap"><textarea></textarea></div><div class="after_text"><a data-action="reply" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only fr" role="button" aria-disabled="false"><span class="ui-button-text">发表</span></a></div></div></div></dd></dl>';

					}
				}
				$("#dialog").html(html);
				$(".txt_ipt").focus(function() {
                    $(this).hide();
                    $(this).closest('.fd-right').find(".comment_input_box").show();
                    $(this).closest('.fd-right').find('.comment_input_box textarea').focus();

                });
                
                // 对话回复
			    $('.fr').click(function() {
			       var did = $(this).closest('.fd-right').attr("data-did");
			       var content = $(this).closest('.fd-right').find('.comment_input_box textarea').val();
			        if (isnull(content)) {
			            $().message("请输入回复内容！");
			            return;
			        }
			        var fun = function(data) {
			            if (data.s == 1) {
			                $("#dcText").val("");
			                // 刷新对话列表
			                searchDialog(dpage);
			            }
			        };
			        exeAjax(
			                ajaxUrl("${aier_url}${aier_urijs}userhscb_commentDialog${aier_suffix}"),
			                fun, {
			                    "did" : did,
			                    "type" : 2,
			                    "content" : content
			                });
			       
			    });
				// 更新分页显示
				if (curTab == 0) {
				    dpage = data.page;
	                toLoadPage(dpage, page_size, data.page_count, data.count, "page", "searchDialog", null, null);
	                if (data.count == 0) {
	                    $("#page").css("display","none");
	                } else {
	                    $("#page").css("display","block");
	                }
				}
				
			}
		};
		exeAjax(
				ajaxUrl("${aier_url}${aier_urijs}userhscb_searchPDialogList${aier_suffix}"),
				fun, {
					"buid" : global_buid,
					"page":dpage,
                    "page_size":page_size
				});
	}
    $("#remark").click(function() {
        curTab = 3;
        searchAppraise(rpage);
    });
	// 获取评语列表
    function searchAppraise(nowpage) {
        rpage = nowpage;
        var fun = function(data) {
            if (data.s == 1) {
                // 刷新评语列表
                var html = "";
                if (data.appraiseList != null) {
                    for ( var i = 0; i < data.appraiseList.length; i++) {
                        var appraise = data.appraiseList[i];
                        html += '<dl class="clearfix"><dt><a class="fd-actor" href=""><img width="50" height="50" src="${get_picturl_url}small/'+appraise.headimg+'"></a></dt>';
                        html += '<dd class="fd-right" data-apid="'+appraise.apid+'">';
                        html += '<div class="fd-top"><a href="">'
                                + appraise.tname + '老师</a> 发送给我的评语 <br><div>'
                                + appraise.content + '</div></div>';
                        html += '<p class="fd-bottom"><span class="fd-actions"><a href="javascript:;" data-action="replyIt" id="replyCount_1399030" data-count="4">回复(<em>'
                                + appraise.acList.length
                                + '</em>)</a></span><span class="time">'
                                + appraise.cdate.split("T")[0]
                                + " "
                                + appraise.cdate.split("T")[1] + '</span></p>';

                        if (appraise.acList != null && appraise.acList.length != 0) {
                            html += '<div id="commentPanel_0" class="comment"><div id="commentList_0" class="comment_list ">';
                            for ( var j = 0; j < appraise.acList.length; j++) {
                                var ac = appraise.acList[j];
                                html += '<dl><dt><a href=""><img src="${get_picturl_url}small/'+ac.headimg+'" width="40" height="40" data-card="" alt=""></a></dt><dd class="ml50"><a href="">'
                                        + ac.cname
                                        + '</a><span class="time">'
                                        + ac.cdate.split("T")[0]
                                        + " "
                                        + ac.cdate.split("T")[1] + '</span>';
                                html += '<a href="javascript:;" data-action="replyComment" data-cid="287736" data-cuid="" data-fromuser="" class="reply">回复</a><div class="content mt5"><div>'
                                        + ac.content
                                        + '</div><div class="media_pre"></div></div></dd></dl>';
                            }
                            html += '</div>';
                        }
                        html += '<div class="sj"></div><input type="text" class="txt_ipt" value="我要回复" data-action="showInputBox"><div style="display: none;" class="comment_input_box"><div class="txt_wrap"><textarea id = "acText"></textarea></div><div class="after_text"><a data-action="reply" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only fr" role="button" aria-disabled="false"><span class="ui-button-text">发表</span></a></div></div></div></dd></dl>';

                    }
                }
                
                $("#appraise").html(html);
                $(".txt_ipt").focus(function() {
                    $(this).hide();
                    $(this).closest('.fd-right').find('.comment_input_box').show();
                    $(this).closest('.fd-right').find('.comment_input_box textarea').focus();

                });
                
                // 评语回复
			    $('.fr').click(function() {
                   var apid = $(this).closest('.fd-right').attr("data-apid");
                   var content = $(this).closest('.fd-right').find('.comment_input_box textarea').val();
			        if (isnull(content)) {
			            $().message("请输入回复内容！");
			            return;
			        }
			        var fun = function(data) {
			            if (data.s == 1) {
			                $("#acText").val("");
			                // 刷新评语列表
			                searchAppraise(rpage);
			            }
			        };
			        exeAjax(
			                ajaxUrl("${aier_url}${aier_urijs}userhscb_commentAppraise${aier_suffix}"),
			                fun, {
			                    "apid" : apid,
			                    "type" : 2,
			                    "content" : content
			                });
			
			    });
			    // 更新分页显示
			    if (curTab == 3) {
				    rpage = data.page;
	                toLoadPage(rpage, page_size, data.page_count, data.count, "page", "searchAppraise", null, null);
	                if (data.count == 0) {
	                    $("#page").css("display","none");
	                } else {
	                    $("#page").css("display","block");
	                }
			    }
			    
            }
        };
        exeAjax(
                ajaxUrl("${aier_url}${aier_urijs}userhscb_searchPAppraiseList${aier_suffix}"),
                fun, {
                    "buid" : global_buid,
                    "page":rpage,
                    "page_size":page_size
                });
    }
    $("#task").click(function() {
        curTab = 1;
        searchHomework(tpage);
    });
    // 查询作业列表
    function searchHomework(nowpage) {
    	tpage = nowpage;
        var fun = function(data) {
            if (data.s == 1) {
                // 作业列表
                if (data.hwList != null) {
                    for ( var i = 0; i < data.hwList.length; i++) {
                        var html = '<dl class="dldldl clearfix" data-mid="" data-srxtype="work"><dt><a class="fd-actor" href=""><img width="50" height="50" data-card="392166" src="" alt="头像"></a></dt><dd class="fd-right" data-hid="3"><div class="fd-top"><span class="new"><a href=""></a>布置了作业</span><div class="homework-content"></div></div><div class="fd-media-pre"><div class="feed_media"><span data-action="showMediaBox"><a href="" target="_blank"><img src="" class="small_pic"></a></span></div></div><p class="fd-bottom"><span class="fd-actions"><a href="javascript:;" data-action="replyIt" data-count="4">回复(<em></em>)</a></span><span class="time"></span></p><div class="comment"><div class="comment_list "></div><div class="comment_input_box"><div class="txt_wrap"><textarea class="border-box"></textarea></div><div class="after_text"><a href="javascript:;" class="aaa">图片</a><a data-action="reply" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only fr" role="button" aria-disabled="false"><span class="ui-button-text">发表</span></a></div></div></div></dd></dl>';
                        $("#homework").append(html);
                        
                        $('.aaa').click(function(event) {
                            event.stopPropagation();
                        });
        
                        
                        $(".aaa").click(function() {
                            $('#uploadPhotoBox').show();
                            var boxTop = $(this).offset().top + $(this).height() + 8,
                                boxLeft= $(this).offset().left;
                            
                            $('#uploadPhotoBox').css({
                                top: boxTop,
                                left: boxLeft
                           });
                         
                        });
                        
                        var target = $('#homework').children('.dldldl').last();
                        
                        target.find('.comment_list dl').remove(); // 移除回复列表
                        var hw = data.hwList[i]; //获取数据
                        /* 插入数据 */
                        target.find('dt a img').attr('src',"${get_picturl_url}small/"+hw.headimg);  //头像
                        target.children('.fd-right').attr('data-hid',hw.hid);        // 作业id
                        target.find('.fd-right .fd-top span a').text(hw.tname+"老师"); // 老师昵称
                        target.find('.fd-right .homework-content').html(hw.content);   // 作业内容，可以先解析
                        target.find('.fd-bottom .fd-actions a em').text(hw.hcList.length); //回复数
                        target.find('.fd-bottom .time').text(hw.cdate.split("T")[0] + " " + hw.cdate.split("T")[1]);
                        
                        if (!isnull(hw.img)) {
                            target.find('span[data-action="showMediaBox"] a').attr('href',"${homework_get_url}origin/"+hw.img) // 原始图跳转
                                .children('img').attr('src',"${homework_get_url}small/"+hw.img); //缩略图
                        } else {
                            target.find('.fd-media-pre').remove(); // 移除作业公告中的图片
                        }
                        
                        // 一级评论列表
                        if (hw.hcList != null && hw.hcList.length != 0) {
                            for ( var j = 0; j < hw.hcList.length; j++) {
                                var hc = hw.hcList[j];
                                var htmlB =  '<dl data-chid=""><dt><a href=""><img src="" width="40" height="40" data-card="" alt=""></a></dt><dd class="ml50"><a href="">昵称</a><span class="time">0000-09-17 17:26:37</span><a href="javascript:;" data-action="replyComment" data-cid="" data-cuid="" data-fromuser="" class="reply">回复</a><div class="content mt5"><div>23</div><a href="" target="_blank" class="comment-img"><img src=""></a></div></dd></dl>'; // 获取回复列表模版
                                target.find('.comment_list').append(htmlB);// 插入数据
                                var targetB = target.find('.comment_list').children('dl').last();
                                targetB.attr('data-chid',hc.chid);
                                targetB.find('dt img').attr('src',"${get_picturl_url}small/"+hc.headimg);
                                targetB.find('.ml50 a:eq(0)').text(hc.cname);
                                targetB.find('.time').text(hc.cdate.split("T")[0] + " " + hc.cdate.split("T")[1]);
                                targetB.find('.content>div:eq(0)').html(hc.content);
                                
                                if (!isnull(hc.img)) {
                                    targetB.find('.content>.comment-img').attr('href',"${homework_get_url}origin/"+hc.img)
                                        .children('img').attr('src',"${homework_get_url}small/"+hc.img);
                                } else {
                                    targetB.find('.content>.comment-img').remove(); // 移除回复中的图片
                                }
                                
                            }
                        }
                    } // end for
                    clickCommentII();
                }
                
                

                // 作业一级评论
                $('.fr').click(function() {
                   var hid = $(this).closest('.fd-right').attr("data-hid");
                   var content = $(this).closest('.fd-right').find('.comment_input_box textarea').val();

                    if (isnull(content)&&isnull(hwImg)) {
                        $().message("请输入回复内容！");
                        return;
                    }
                    var fun = function(data) {
                        if (data.s == 1) {
                            $("#hcText").val("");
                            hwImg = "";
                            $('#confirmPhoto').hide();
                            $('#selectPhoto').val("");
                            $('#photoName').html("");
                            $('.select').show();
                            // 刷新作业列表
                            $("#homework").html('');
                            searchHomework(tpage);
                        }
                    };
                    exeAjax(
                            ajaxUrl("${aier_url}${aier_urijs}userhscb_commentHomework${aier_suffix}"),
                            fun, {
                                "hid" : hid,
                                "type" : 2,
                                "content" : content,
                                "imageName":hwImg,
                                "buid":global_buid
                            });
                });
                // 更新分页显示
                if (curTab == 1) {
                    tpage = data.page;
                    toLoadPage(tpage, page_size, data.page_count, data.count, "page", "searchHomework", null, null);
                    if (data.count == 0) {
                        $("#page").css("display","none");
                    } else {
                        $("#page").css("display","block");
                    }
                }
                
            }
        };
        exeAjax(
                ajaxUrl("${aier_url}${aier_urijs}userhscb_searchPHomework${aier_suffix}"),
                fun, {
                	"buid" : global_buid,
                    "page":tpage,
                    "page_size":page_size
                });
        
    }
    $("#bulletin").click(function() {
        curTab = 2;
        searchSchoolMessage(bpage);
    });
    //查询公告
    function searchSchoolMessage(nowpage){
        bpage = nowpage;								
        var fun = function(data) {
        	var meghtml = "";
            if (data.s == 1) {
                for(var i=0;i<data.schoolMessageList.length;i++) {
                  	var name_teacher = data.schoolMessageList[i].name_teacher;
                  	var headimg_teacher = data.schoolMessageList[i].headimg_teacher;
     				var message = data.schoolMessageList[i].message;
     				var ctime_str = data.schoolMessageList[i].ctime_str;
     				var type_m = data.schoolMessageList[i].type;
     				var img = data.schoolMessageList[i].img;
     				var type_str = "班级公告";
     				if(type_m==0){
     					type_str = "校园公告";
     				};
     				meghtml += "<div class='fd-item'><dl class='clearfix'><dt><a class='fd-actor' href=''> <img width='50' height='50' data-card='392161'"+
     					"src='${get_picturl_url}small/"+headimg_teacher+"' alt='"+name_teacher+"' title='"+name_teacher+"'> </a></dt>"+
     					"<dd class='fd-right'><div class='fd-top'><span><a href=''>"+name_teacher+"老师</a>发布了"+type_str+"</span>"+
     					"<div>"+message+"</div>";
     				// 有图片
                    if (!isnull(img)) {
                        meghtml += "<div class='feed_media'><span data-action='showMediaBox'><a href='${homework_get_url}origin/"+
                        img+"' target='_blank'><img src='${homework_get_url}small/"+img+"' class='small_pic'></a></span></div>";
                    }
                    meghtml += "</div><p class='fd-bottom'><span class='time'>"+ctime_str+"</span></p></dd></dl></div>";	
     			}
     			// 更新分页显示
     			if (curTab == 2) {
	     			bpage = data.page;
	                toLoadPage(bpage, page_size, data.page_count, data.count, "page", "searchSchoolMessage", null, null);
	                if (data.count == 0) {
	                    $("#page").css("display","none");
	                } else {
	                    $("#page").css("display","block");
	                }
                }
            }
            $("#userBulletin").html(meghtml);
        };
        exeAjax(
                ajaxUrl("${aier_url}${aier_urijs}userhscb_searchSchoolMessageList${aier_suffix}"),
                fun, { 
                    "cid" : global_cid,
                    "page":bpage,
                    "page_size":page_size
                });   
    }
    
    // 查询进出园记录
    $("#record").click(function() {
        curTab = 4;
        $("#page").css("display","none");
        searchStuIcardInfoList();
    });
    
    
    //绑定宝宝ic卡    
    $("#iccard").click(function() {
        curTab = 5;
        $("#page").css("display","none");
    });
    
    function bindStuCard(){
        $("#page").css("display","none");
		var cardNum = $("#cardTxt").val().trim();
		var cardfoot = $("#codeTxt").val().trim();
        if (cardNum==""||cardfoot=="") {
            $().message("请输入卡号和验证码！");
            return;
        }
        if(cardNum.length!=8){
        	$().message("请输入8位卡号！");
        	return;
        }
        var fun = function(data) {
            if (data.s == 1) {
                $().message("绑定成功");
                $("#schoolCardInfo").trigger("reloadGrid");
            }else{
            	$().message("绑定失败!"+data.error_info);
            }
        };
        exeAjax(
                ajaxUrl("${aier_url}${aier_urijs}userhscb_addStudentIcard${aier_suffix}"),
                fun, {
                    "cardNum" : cardNum,
                    "cardfoot" : cardfoot,
                    "cid" : global_cid,
                    "buid":global_buid
                });
    }
    
    // 上传图片

	$("body").click(function(){
	    $("#uploadPhotoBox").hide();
	});
	
	$('.upload_img,#uploadPhotoBox').click(function(event) {
	    event.stopPropagation();
	});
	
	$(".upload_img").click(function() {
	    
	    var boxTop = $(this).offset().top + $(this).height() + 8,
	        boxLeft= $(this).offset().left;
	    
	    $('#uploadPhotoBox').css({
	     top: boxTop,
	        left: boxLeft
	   });
	 
	    $('#uploadPhotoBox').toggle();
	
	});
	
	$("#selectPhoto").live('change', function(){
        upfile();
        $(".select").hide();
        $(".uploading").show();
    });
    
    function upfile() {
        var temp = $('#selectPhoto').val().substring($('#selectPhoto').val().lastIndexOf('.')).toLowerCase();
        try {$.ajaxFileUpload({
            url : "${aier_url}commonjs/image_uploadImage${aier_suffix}?photoName="+temp+"&&imageUrl=${homework_upload_url}&&type=1",
            secureuri : false,
            fileElementId : 'selectPhoto',
            dataType : 'json',
            success : function(data, status) {
                if (data.s == 1) {
                    hwImg = data.imageName;
                    $(".uploading").hide();
                    $('#confirmPhoto').show();
                    $('#photoName').html(hwImg);
                } else {
                    $().message("图片上传出错，请重新上传！");
                    $(".uploading").hide();
                    $('.select').show();
                }
                
            },
            error : function(data, status, e) {
                $().message("服务器连接超时");
                
            }
        });
        } catch (e) {
            $(".uploading").hide();
            $('.select').show();
            $().message("服务器连接超时");
        }
    };
    
    // 删除图片
    $("#delete").click(function(){
         var fun=function(data){
            if(data.s==1){
                hwImg = "";
                $('#confirmPhoto').hide();
                $('#selectPhoto').val("");
                $('#photoName').html("");
                $('.select').show();
            } else {
                $().message("删除失败，请稍后再试！"); 

            }
        };
        exeAjax(
             ajaxUrl("${aier_url}${aier_urijs}userhomeforums_deleteImage.shtml"),
             fun,{
                 "imageName":hwImg
        });
        
    });
    
    $("#daily").click(function() {
       $("#page").css("display","none");
    });
    
 // Z000056 2013-09-23

    function clickCommentII() {
        
        $('.ml50 .reply').click(function(){

            var $target = $(this).parent('.ml50');
            if ($target.hasClass('replying')) {
                $target.removeClass('replying');
                $target.children('.usb-hw-comment-ii').remove();
            } else {
                $target.addClass('replying');
                searchCommentII($target);
            }
        });
    }

    function searchCommentII($target) {
        // ajax过程

        var commentii = '<div class="usb-hw-comment-ii"><div class="comment-textbox"><div class="edit"><textarea class="border-box"></textarea></div><div class="func clearfix"><a class="btn btn-reply btn-orange-2"><span>回复</span></a></div></div><div class="comment-list-ii"><div class="comment-item-ii clearfix"><div class="avatar"><a href=""><img src="" alt=""></a></div><div class="name"><a href=""><span class="nickname"></span></a><span class="birthtime"></span></div><div class="words"></div></div></div></div>'; // 模版文件
        var $cmtall = $(commentii); // dom,子回复（框+列表）
        $cmtall.find('.comment-item-ii').remove(); // 清空子回复列表
        var chid = $target.parent('dl').attr('data-chid');
        // 插数据过程
        var fun = function(data) {
            if (data.s == 1) {
                if (data.hcrList != null) {
                    $target.append($cmtall); // 先输出不包含子回复列表的html
                    /* 子回复列表>0 */
                    var $targetList = $target.find('.comment-list-ii');
                    for (var i = 0; i < data.hcrList.length; i++) {
                        var $cmtitem = $(commentii).find('.comment-item-ii'); // dom,单个子回复项目
                        var hcr = data.hcrList[i];
                        // 插数据过程
                        $cmtitem.find('.avatar img').attr('src',"${get_picturl_url}small/"+hcr.headimg);
                        $cmtitem.find('.name .nickname').text(hcr.cname);
                        $cmtitem.find('.name .birthtime').text(hcr.cdate.split("T")[0]+ " "+hcr.cdate.split("T")[1]);
                        $cmtitem.find('.words').text(hcr.content);

                        $targetList.prepend($cmtitem); // 输出子回复列表
                    };
                }
                
            }
            replyCommentII(commentii,chid,$target);
        };
        exeAjax(
                ajaxUrl("${aier_url}${aier_urijs}userhscb_searchHWCReply${aier_suffix}"),
                fun, {
                    "chid" : chid
                });

        
    }

    function replyCommentII(commentii,chid,$target) {
        $target.find('.btn-reply').click(function(){
            var $this = $(this);
            var words = $this.parents('.comment-textbox').find('textarea').val();
            if (isnull(words)) {
                $().message("请输入回复内容！");
                return;
            }
            var fun = function(data) {
                if (data.s == 1 && data.hcr != null) {
                    $this.parents('.comment-textbox').find('textarea').val("");
                    var $list = $this.parents('.usb-hw-comment-ii').find('.comment-list-ii');
                    var $cmtitem = $(commentii).find('.comment-item-ii');
                    
                    // 插数据过程
                    $cmtitem.find('.avatar img').attr('src',"${get_picturl_url}small/"+data.hcr.headimg);
                    $cmtitem.find('.name .nickname').text(data.hcr.cname);
                    $cmtitem.find('.name .birthtime').text(data.hcr.cdate.split("T")[0]+ " "+data.hcr.cdate.split("T")[1]);
                    $cmtitem.find('.words').text(data.hcr.content);
                    $list.prepend($cmtitem);
                }
            };
            exeAjax(
                    ajaxUrl("${aier_url}${aier_urijs}userhscb_replyComment${aier_suffix}"),
                    fun, {
                        "chid" : chid,
                        "content":words,
                        "type":2,
                        "buid":global_buid
                    });
            
        });
    }
    
</script>
</html>